<?php

namespace app\api\controller;

use fast\Random;
use think\App;
use think\facade\Validate;
use think\facade\Config;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\controller\Api;
use think\Request;

/**
 * 会员接口.
 */
class User extends Api
{
    protected $noNeedLogin = ['wechatLogin', 'config', 'getPhoneNumber'];
    protected $noNeedRight = '*';

    protected $model = null;

    /**
     * 构造方法
     * @access public
     * @param Request $request Request 对象
     */
    public function __construct(Request $request = null)
    {
        parent::__construct(App::getInstance());
        $this->model = new \app\api\model\User();
    }

    public function _initialize()
    {
        parent::_initialize();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }

    /**
     *  小程序登录
     */
    public function wechatLogin(){
        $requestData = $this->requestData;
        $data  = $this->model->wechatLogin($requestData);
        $this->getReturnData($data);
    }

    /**
     *  授权手机号
     */
    public function getPhoneNumber(){
        $requestData = $this->requestData;
        $data  = $this->model->getPhoneNumber($requestData);
        $this->getReturnData($data);
    }

    /**
     * 我的首页.
     */
    public function mine()
    {
        $requestData = $this->requestData;
        $user = $this->auth->getUserinfo();
        $data  = $this->model->mine($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 公共参数.
     */
    public function config()
    {
        $requestData = $this->requestData;
        $data  = $this->model->config($requestData);
        $this->getReturnData($data);
    }

    /**
     * 意见反馈.
     */
    public function feedback()
    {
        $requestData = $this->requestData;
        $user = $this->auth->getUserinfo();
        $data  = $this->model->feedback($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 注销登录.
     */
    public function logout()
    {
        $this->auth->logout();
        $data = ['status' => 1, 'message' => '操作成功', 'result' => ''];
        $this->getReturnData($data);
    }

}
